/**
 * Generali Solutions d'assurances - Tous droits réservés &copy; 2007 - 2010
 */
package fr.generali.accueilclient.commun.tosca;

import java.util.Calendar;

import javax.xml.datatype.XMLGregorianCalendar;

/**
 * @author Holmes Kelly
 */
public final class CalendarHelper {

    /**
     * 
     */
    private CalendarHelper() {

    }

    /**
     * Sets the values for the calendar fields <code>YEAR</code>,
     * <code>MONTH</code>, and <code>DAY_OF_MONTH</code>. Previous values of
     * other calendar fields are retained. If this is not desired, call
     * {@link #clear()} first.
     * 
     *@param calendar calendar to set
     * @param year the value used to set the <code>YEAR</code> calendar field.
     * @param month the value used to set the <code>MONTH</code> calendar field.
     *            Month value is 0-based. e.g., 0 for January.
     * @param date the value used to set the <code>DAY_OF_MONTH</code> calendar
     *            field.
     * @return boolean check
     */
    public static Boolean set(Calendar calendar, int year, int month, int date) {

        Boolean isCalendarValide = null;

        if (calendar == null) {
            isCalendarValide = false;
            throw new NullPointerException("calendar null");
        }

        calendar.clear();

        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month);
        calendar.set(Calendar.DATE, date);
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        isCalendarValide = true;

        return isCalendarValide;
    }

    /**
     * @param xmlGregorianCalendar xml gregorian calendar
     * @param year year
     * @param month month
     * @param date date
     * @return boolean check
     */
    public static Boolean setXmlGregorianCalendar(XMLGregorianCalendar xmlGregorianCalendar, int year, int month,
                    int date) {

        Boolean isGregorianCalendarValide = null;

        if (xmlGregorianCalendar == null) {
            isGregorianCalendarValide = false;
            throw new NullPointerException("gregorian calendar null");
        }

        xmlGregorianCalendar.setYear(year);
        xmlGregorianCalendar.setMonth(month);
        xmlGregorianCalendar.setDay(date);

        isGregorianCalendarValide = true;

        return isGregorianCalendarValide;
    }

}
